package org.brisling.satisfaction.queryService;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.brisling.base.domain.ListDomain;
import org.brisling.base.service.AbstractBaseQueryService;
import org.brisling.common.ConstSysParam;
import org.brisling.common.exception.DangerousOperatorException;
import org.brisling.mobile.vo.satis.VOSubject;
import org.brisling.satisfaction.domain.SatisfactionEvaluateSubject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/satisfactionEvaluateSubject/query")
public class QuerySatisfactionEvaluateSubjectService extends AbstractBaseQueryService<SatisfactionEvaluateSubject>{
	
	public QuerySatisfactionEvaluateSubjectService(){
		this.moduleName = ConstSysParam.MODULE_SATISFACTION_EVALUATE_SUBJECT;
		this.subSystem = ConstSysParam.SUBSYSTEM_STATISFACTION;
		this.tableName = ConstSysParam.VIEW_PREFIX +this.moduleName;
		this.clazz = SatisfactionEvaluateSubject.class;	
		orderMap.put("evaluateat","desc");	
	}
	
	@PersistenceContext(unitName=ConstSysParam.SUBSYSTEM_SYSMAN)
	@Autowired
	protected void setEntityManager(EntityManager entityManager){
		this.entityManager = entityManager;		
	}
	
	
	public ListDomain<SatisfactionEvaluateSubject> getListDomain(String evaluate_type) {	
		String sql = "SELECT * FROM V_SATIS_EVALUATE_SUBJECT "
				   + "WHERE evaluate_type = %1$s AND is_del IS NULL ORDER BY sort";
		sql = String.format(sql, evaluate_type);
		return super.getSqlListDomain(sql);
	}
	
	@RequestMapping("/getList.action")
	public List<SatisfactionEvaluateSubject> getList(String evaluate_type) {
		
		String sql = "SELECT * FROM V_SATIS_EVALUATE_SUBJECT "
				   + "WHERE evaluate_type = %1$s AND is_del IS NULL ORDER BY sort";
		sql = String.format(sql, evaluate_type);
		return super.getAllList(sql);
	}
	
	@RequestMapping("/getAppList.action")
	public List<VOSubject> getAppList(String evaluate_type) {
		
		String sql = "SELECT * FROM V_SATIS_EVALUATE_SUBJECT "
				   + "WHERE evaluate_type = %1$s AND is_del IS NULL ORDER BY sort";
		sql = String.format(sql, evaluate_type);
		List<VOSubject> lists = null;
		try {
			lists = super.getClassedAllList(sql,VOSubject.class);
		} catch (DangerousOperatorException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return lists;
	}
	
}
